/*
 *  Copright: 2008 Philipp Leitner, Distributed Systems Group,
 *            TU Wien, leitner@infosys.tuwien.ac.at
 *
 *  This file is part of DAIOS.
 *
 *  DAIOS is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation.
 * 
 *  DAIOS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with DAIOS.  If not, see
 *  <http://www.gnu.org/licenses/>.
 * 
 */

package at.ac.tuwien.infosys.dsg.daios.wsdl;

/**
 * A simple struct that defines a WSDL encoding
 * style. Such a style consists of 2 parts:
 * 
 * <pre>
 *   -- The 'invocation style' (document or rpc).
 *   -- The 'encoding style' (encoded or wrapped).
 * </pre>
 * 
 * The WSDLEncoding struct is immutable.
 * 
 * @author philipp
 *
 */
public class WSDLEncoding {
	
	private String invStyle = null;
	private String encStyle = null;
	
	/**
	 * Construct a new WSDLEncoding style.
	 * 
	 * @param invStyle
	 * @param encStyle
	 */
	public WSDLEncoding(String invStyle, String encStyle) {
		this.invStyle = invStyle;
		this.encStyle = encStyle;
	}
	
	public String getInvocationStyle() {
		return invStyle;
	}
	
	public String getEncodingStyle() {
		return encStyle;
	}
	
	/**
	 * WSDLEncodings are equal when invocation style
	 * as well as encoding style are equal. 
	 */
	public boolean equals(Object o) {
		if(o == null)
			return false;
		if(! (o instanceof WSDLEncoding))
			return false;
		WSDLEncoding other = (WSDLEncoding)o;
		if(this.invStyle.equals(other.getInvocationStyle()) &&
			this.encStyle.equals(other.getEncodingStyle()))
			return true;
		else
			return false;
	}
	
	/**
	 * We have a very simple hashing startegy here:
	 * 
	 * <pre>
	 *   hashCode = hash(invocation) + hash(encoding)
	 * </pre>
	 */
	public int hashCode() {
		return invStyle.hashCode()+encStyle.hashCode();
	}
	
	public String toString() {
		return invStyle+"/"+encStyle;
	}
}
